package com.dm.controller;

import com.dm.client.dm_item.RestDmItemCommentClient;
import com.dm.dto.Dto;
import com.dm.dto.DtoUtil;
import com.dm.pojo.dm_item.DmItem;
import com.dm.pojo.dm_item.DmItemComment;
import com.dm.service.ItemDetailService;
import com.dm.vo.DmItemVo;
import com.dm.vo.HotItemVo;
import com.dm.vo.ItemCommentVo;
import com.dm.vo.ItemDetailVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 商品详情界面contorller
 */
@RestController
@RequestMapping("/item/api")
public class ItemDetailController {
    @Resource
    private ItemDetailService itemDetailService;
    @Resource
    private RestDmItemCommentClient restDmItemCommentClient;

    /*@Resource
    private LogUtils logUtils;*/



    /**
     * 推荐接口
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/queryItemRecommend", method = RequestMethod.POST)
    public Dto<HotItemVo> queryBanner() throws Exception {
        List<HotItemVo> hotItemVoList = itemDetailService.queryBanner();
        return DtoUtil.returnDataSuccess(hotItemVoList);
    }


    /**
     * 根据商品id返回商品详情页
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/queryItemDetail", method = RequestMethod.POST)
    public Dto<ItemDetailVo> queryItemDetail(@RequestParam("id") String id) throws Exception {
        //日志
        //logUtils.i(Constants.TOPIC.ITEM_CONSUMER, "查询商品id为" + id + "信息");
        return itemDetailService.queryItemDetail(Long.parseLong(id));
    }

    /**
     * 根据商品ID查询商品排期
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/queryItemScheduler", method = RequestMethod.POST)
    public Dto queryItemScheduler(String id) throws Exception {
        return DtoUtil.returnDataSuccess(itemDetailService.getItemSchedulerById(id));
    }

    /**
     * 根据商品排期查询商品价格
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/queryItemPrice", method = RequestMethod.POST)
    public Dto queryItemPrice(String id) throws Exception {

        return DtoUtil.returnDataSuccess(itemDetailService.queryItemPrice(id));
    }

    /**
     * 根据商品id查询剧评
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/queryItemComment", method = RequestMethod.POST)
    public Dto queryItemComment(String id) throws Exception {

        return DtoUtil.returnDataSuccess(itemDetailService.queryItemComment(id));
    }

    /**
     * 添加剧评
     * @param dmItemComment
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/commitItemComment", method = RequestMethod.POST)
    public Dto commitItemComment(@ModelAttribute("dmItemComment") DmItemComment dmItemComment) throws Exception {
        dmItemComment.setCreatedTime(new Date());
        restDmItemCommentClient.qdtxAddDmItemComment(dmItemComment);
        return DtoUtil.returnSuccess("");
    }
}
